#!/usr/bin/env bash
# Author: Nicola Lunghi
# script to compile and add acpi hooks 
# use like this: acpi-add file1.asl file2.asl 

BASEHOOKSDIR="/lib/firmware/acpi-upgrades"

count=0

for arg in "$@"
do
    fullname=$(basename "$arg")
    extension="${fullname##*.}"
    filename="${fullname%.*}"

    if [ -f "$fullname" ] && [ "$extension" == "asl" ]
    then
        ((count++))
        echo "-- generating ${fullname}"
        iasl ${filename}.asl > /dev/null
        sudo mv $filename.aml $BASEHOOKSDIR
    fi
done

echo -e "\nAdded ${count} asl files\n" 

if [ "$count" -ne "0" ]
then
    echo -e "\nUpdate initramfs...\n"
    # update initramfs
    sudo update-initramfs -u -k all
    echo -e "\nDone\n"
fi


